package com.jt.controller;

import com.jt.pojo.Item;
import com.jt.pojo.ItemDesc;
import com.jt.service.ItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * @author dc
 * @Classname ItemController
 * @Date 2020/2/22 17:57
 */
@Controller
@RequestMapping("/items")
public class ItemController {

    @Autowired
    ItemService itemService;

    /**
     * url:http://www.jt.com/items/562379.html
     * 用户接收url之后,动态调取商品信息(item+itemDesc)
     * 用户接收数据后在item.jsp展现
     * 获取方式:${item.title},${itemDesc.itemDesc}
     * @param itemId
     * @param model
     * @return
     */
    @RequestMapping("/{itemId}")
    public String findItemById(@PathVariable Long itemId, Model model){
        Item item = itemService.findItemById(itemId);
        ItemDesc itemDesc=itemService.findItemDescById(itemId);
        String itemParam=itemService.findItemParamById(itemId);
        model.addAttribute("item",item);
        model.addAttribute("itemDesc",itemDesc);
        model.addAttribute("itemParam",itemParam);
        return "item";
    }

}
